In [1]:
#%matplotlib inline
import pandas as pd
import platform
import sys
import numpy as np
from datetime import datetime, date, timedelta
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib
#from pylab import rcParams
#rcParams['figure.figsize'] = 15, 10
In [2]:
import wellapplication as wa
In [3]:
print("Operating System " + platform.system() + " " + platform.release())
print("Python Version " + str(sys.version))
print("Pandas Version " + str(pd.__version__))
print("Numpy Version " + str(np.__version__))
print("Matplotlib Version " + str(matplotlib.__version__))
print("Well Application Version " + str(wa.__version__))
Call usgs
class of wellapplication
In [4]:
USGS = wa.usgs()
Set working environment.
In [ ]:
rootlocal = 'E:/GIS/'
Read in data prepared by ArcGIS.
In [5]:
matchedStations = pd.read_csv(rootlocal + "USGS_WL_WELLS_HUCS.txt")
Show columns in imported column.
In [6]:
matchedStations.columns
Out[6]:
Get list of stations for each groundwater area.
In [7]:
stationLists = matchedStations.groupby(['GWArea'])['site_no'].unique()
Create dictionary matching HUC names to HUC 8 codes.
In [9]:
nameit = pd.Series(matchedStations.Name.values, index = matchedStations.HUC8).to_dict()
Generate site and data files from HUC 8 in list.
In [ ]:
sites = {}
data = {}
areaList = list(matchedStations.HUC8.unique())[1:]
for area in areaList:
try:
sites[area] = USGS.getStationInfoFromHUC(area)
data[area] = USGS.getWLfromHUC(area)
print area
except:
print("no data for " + str(area))
pass
Combine dictionaries into a complete data and stations file.
In [ ]:
allsites = pd.concat(sites)
alldata = pd.concat(data)
Save files as csv files and an excel file.
In [ ]:
allsites.to_csv(rootlocal + 'USGSSites.csv')
alldata.to_csv(rootlocal + 'USGSData.csv')
In [ ]:
writer = ExcelWriter(rootlocal + 'USGS_WL_UT.xlsx')
allsites.to_excel(writer,'sites')
alldata.to_excel(writer,'data')
writer.save()
Generate and save plots to a pdf file. Skip error files.
In [ ]:
pdf_pages = PdfPages(rootlocal + 'HydrographSummary.pdf')
for area in areaList:
try:
plots = USGS.HUCplot(sites[area],data[area])
fig = plots[0]
fig.suptitle(str(area) + " = " + nameit[area])
pdf_pages.savefig(fig)
plt.close(fig)
fig2 = plots[1]
fig2.suptitle(str(area) + " = " + nameit[area])
pdf_pages.savefig(fig2)
plt.close(fig2)
print(str(area) + " = " + nameit[area])
except:
print("no plot for " + str(area) + " = " + str(nameit[area]))
pass
# Write the PDF document to the disk
pdf_pages.close()
In [ ]:
area = 16020302
pdf_pages = PdfPages(rootlocal + 'E:/GIS/HydrographSummarySingle.pdf')
plots = USGS.HUCplot(sites[area],data[area])
fig = plots[0]
fig.suptitle(str(area) + " = " + nameit[area])
pdf_pages.savefig(fig)
plt.close(fig)
fig2 = plots[1]
fig2.suptitle(str(area) + " = " + nameit[area])
pdf_pages.savefig(fig2)
plt.close(fig2)
print(str(area) + " = " + nameit[area])
pdf_pages.close()